package com.ruoyi.business.controller;


import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.business.domain.ReceivingBillentryHand;
import com.ruoyi.business.domain.ReceivingBillentryPound;
import com.ruoyi.business.service.ReceivingBillentryPoundService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 收货物料明细地磅数据Controller
 *
 * @author JerryLu
 * @date 2024/8/29 18:15
 * @return
 */
@RestController
@RequestMapping("/system/receiving_billentry_pound")
public class ReceivingBillentryPoundController extends BaseController {
    @Autowired
    private ReceivingBillentryPoundService poundService;

    /**
     * 查询收货物料明细列表
     */
    @PreAuthorize("@ss.hasPermi('system:receiving_billentry_pound:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReceivingBillentryPound billentryPound) {
        startPage();
        List<ReceivingBillentryPound> list = poundService.queryList(billentryPound);
        return getDataTable(list);
    }

    /**
     * 导出收货物料明细列表
     */
    @PreAuthorize("@ss.hasPermi('system:receiving_billentry_pound:export')")
    @Log(title = "收货物料明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReceivingBillentryPound billentryPound) {
        List<ReceivingBillentryPound> list = poundService.queryList(billentryPound);
        ExcelUtil<ReceivingBillentryPound> util = new ExcelUtil<ReceivingBillentryPound>(ReceivingBillentryPound.class);
        util.exportExcel(response, list, "收货物料明细地磅数据数据");
    }

    /**
     * 获取收货物料明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:receiving_billentry_pound:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(poundService.getById(id));
    }

    /**
     * 获取收货物料明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:note:index')")
    @GetMapping(value = "/receiving/{receivingId}")
    public AjaxResult getReceiptInfo(@PathVariable("receivingId") String receivingId) {
        QueryWrapper<ReceivingBillentryPound> query = Wrappers.query();
        query.eq("receiving_id", receivingId);
        List<ReceivingBillentryPound> list = poundService.list(query);
        return success(list);
    }

    /**
     * 新增收货物料明细
     */
    @PreAuthorize("@ss.hasPermi('system:receiving_billentry_pound:add')")
    @Log(title = "收货物料明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReceivingBillentryPound billentryPound) {
        return toAjax(poundService.save(billentryPound));
    }

    /**
     * 修改收货物料明细
     */
    @PreAuthorize("@ss.hasPermi('system:receiving_billentry_pound:edit')")
    @Log(title = "收货物料明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReceivingBillentryPound billentryPound) {
        if (billentryPound.getId() != null && billentryPound.getId() > 0) {
            return toAjax(poundService.updateById(billentryPound));
        } else {
            return toAjax(poundService.save(billentryPound));
        }
    }

    /**
     * 删除收货物料明细
     */
    @PreAuthorize("@ss.hasPermi('system:receiving_billentry_pound:remove')")
    @Log(title = "收货物料明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(poundService.removeByIds(Arrays.asList(ids)));
    }
}

